<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
	<title>api</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../css/buyRecord.css" />
</head>

<body >
<script id="buyRecord-template" type="text/x-dot-template">
{{if(it==''){}}
		<div style='padding-top: 40px;color: #999;text-align: center'>该用户还没有购买记录！</div>
	{{}}}
	{{ for(var i=0; i< it.length; i++) { }}
		<dd style="position: relative" class="buy-item" >
		{{if(it[i].yunjiage==10){}}
          <img src="../image/ten.png" class="ico ico-label ico-label-goods">
          {{}}}
				<div style="position: relative" class="item-top align-items">
					<div class="item-img" onclick="openGoodsDetail({{=it[i].id}})">
						<img src="http://wap.jqmao.cn/statics/uploads/{{=it[i].thumb}}" width="82px" height="82px">
					</div>
					<div class="item-content">
						<div class="content-txt">
							<p onclick="openGoodsDetail({{=it[i].id}})" class="title">第({{=it[i].qishu}})期{{=it[i].title}}</p>
							<div  onclick="openHeader('buyCode','{{=it[i].id}}','{{=it[i].uid}}')" style="height: 30px;line-height: 30px; font-size: 14px;">
								<p class="gray">本期参与：{{=it[i].gonumber}}人次<span class='blue'>参与详情</span></p>
							</div>
							
						</div>
					</div>
				</div>
			<div class="item-bottom">
					{{if(it[i].remark=='1'){}}
						<div class="item-bottom">
					<div class="winname" onclick="openWin('userCore','{{=it[i].q_uid}}')"><span>获奖者:</span><span class="blue nametxt">{{=it[i].q_user}}</span>&nbsp;<span class="red">{{=it[i].totalVisitors}}</span><span>人次</span></div>
					
						
					<div  class='button'>
						<span>购买新期</span>
					</div>
					
				</div>
					{{}else{}}
					
						<div class="w-progressBar">
						
						<p class="wrap">
							<span class="bar" style="width:{{=it[i].percent}}%;"> <i class="color"></i>
							</span>
						</p>
						<span class="txt aggregate gray">
							总需: {{=it[i].zongrenshu}}
						</span>
						
						<span class="txt right gray">
							剩余: {{=it[i].shenyurenshu}}
						</span>
					
					</div>
					<div class='button'>
						<span onclick="addCart({{=it[i].id}},'buy')">我也来买</span>
					</div>
					
				</div>
				{{}}}
				<!-- <div class="item-bottom">
					<div class="winname">获奖者：<span class="blue">{{=it[i].q_user}}</span>&nbsp;<span class="red">10</span>人次</div>
					
						
					
					<div  class='button'>
						<span>购买新期</span>
					</div>
					
				</div> -->
				
			</dd>
	{{}}}
</script>


	<div id='buyRecord'>
		<dl id='buyRecord-content'>

		</dl>
		
	</div>

</body>

	<script type="text/javascript" src="../script/zepto.min.js"></script>

	<script type="text/javascript" src="../script/api.js"></script>
	
	<script src='../script/swipe.js'></script>
	<script type="text/javascript" src="../script/doT.min.js"></script>
	<script type="text/javascript" src="../script/common.js"></script>


<script type="text/javascript">
	 function _openWin(name,id) {
    
    if(id){
        pageParam = {id: id}
    }else{
        pageParam = ''
    }
    api.openWin({
        name: name,
        url: name + '.html',
        opaque: true,
        vScrollBarEnabled: false,
        delay: 200,
        pageParam:pageParam

    });
}

apiready = function(){
  var name = api.frameName;
	setbounces(name,true);
	var total = '';
    var uid = api.pageParam.uid;
    getBuyRecord(uid,true);
    function getBuyRecord(uid,isReload,currentPage) {
    var pageSize = 10;
    currentPage=isReload?0:currentPage;
    	api.ajax({
        url: 'http://wap.jqmao.cn/getProgressRecord',
        method: 'post',
        data: {
            values: {uid: uid, pageSize: pageSize,currentPage:currentPage}
        }
    }, function (ret, err) {

        if (ret) {
        	
            total = ret['total']
            var content = $api.byId('buyRecord-content');
            var tpl = $api.byId('buyRecord-template').text;
            var tempFn = doT.template(tpl);
            //alert($api.getStorage('type'));
            //alert(type)
            api.hideProgress();

            if (isReload) {
                 $api.setStorage("currentPage", 0);        // 重新设置为0
                $api.html(content, tempFn(ret['listItems']));
                
            } else {
                $api.append(content, tempFn(ret['listItems']));
            }


        } else {
           //alert(JSON.stringify(err));
        }
        
    });
    }
 //下拉刷新
    api.setCustomRefreshHeaderInfo({
            bgColor : '#f0f0f0',
            image: {
        pull: 'widget://image/refresh/1.png', 
        transform: [
            'widget://image/refresh/1.png', 
            'widget://image/refresh/2.png',
            'widget://image/refresh/3.png',
            'widget://image/refresh/4.png',
            'widget://image/refresh/5.png',
            'widget://image/refresh/6.png',
            'widget://image/refresh/7.png'
        ],
        load: [ 
            'widget://image/refresh/1.png', 
            'widget://image/refresh/2.png',
            'widget://image/refresh/3.png', 
            'widget://image/refresh/4.png',
            'widget://image/refresh/5.png'
        ]
    }
        }, function() {
            //下拉刷新被触发，自动进入加载状态，使用 api.refreshHeaderLoadDone() 手动结束加载中状态
            setTimeout(function(){
             
           var typeName = $api.getStorage('type');
       getBuyRecord(uid,true);
     
        api.refreshHeaderLoadDone();
	            }, 800);
           
      });
  


//上拉加载
    api.addEventListener({

        name: 'scrolltobottom',
        extra: {
            threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
        }
    }, function (ret, err) {
        $("#more").show();
        
        var _page=parseInt($api.getStorage("currentPage"));
        if(_page+10<=total){

         getBuyRecord(uid,false,_page+10);
        $api.setStorage("currentPage", _page+10); // 页码+1
        }else{
            $("#more").hide();
        }
      
       
    });

    

}

    
</script>
</html>